<template>
    <div class="template-form-Lu">
        <a-modal
            title=""
            :visible="applicationFormVisible"
            :maskClosable="false"
            :closable="true"
            :destroyOnClose="true"
            width="100%"
            :dialog-style="{ margin: '0 auto' }"
            wrapClassName="form-modal-Lu"
            @cancel="closeVisible">
            <template slot="footer">
                <div v-if="linkName == '我的已办'">
                    <a-button class="blue-btn" @click="closeVisible">关闭</a-button>
                </div>
                <div v-else>
                    <a-button @click="onSave('保存')">
                        保存
                    </a-button>
                    <a-button :loading="loading" class="blue-btn" @click="onSubmit('提交')">
                        提交
                    </a-button>
                    <a-button v-if="linkName !== '出差申请'" class="red-btn" @click="returnClick">
                        退回
                    </a-button>
                </div>
            </template>
            <a-tabs type="card" v-if="applicationFormVisible" @change="callback">
                <a-tab-pane key="1" tab="申请表">
                    <div id="printTest" class="print-div-shu blue-table" style="height: auto;">
                        <a-form-model
                            ref="ruleForm"
                            :model="form"
                            :rules="rules"
                            :label-col="labelCol"
                            :wrapper-col="wrapperCol"
                            class=""
                        >
                            <h1 class="h1-page">xx壮族自治区食品药品审评查验中心<br/>公务出差审批表</h1>
                            <div v-if="linkName !== '出差申请'" class="table-lu-header" style="display: flex;justify-content: space-between;">
                                <span><span style="color: #5ca3e5;">填报单位：</span><span >{{form.ftbdw}}</span></span>
                                <span><span style="color: #5ca3e5;">填报时间：</span><span >{{form.ftbsj}}</span></span>
                            </div>
                            <table border="1" cellspacing="0" class="table-Lu gwcc-table">
                                <tr>
                                    <th>姓名</th>
                                    <td>{{form.fxm}}</td>
                                    <th>出差地点</th>
                                    <td v-if="linkName == '出差申请'">
                                        <a-form-model-item prop="fccdd">
                                            <a-textarea v-model="form.fccdd" placeholder="出差地点:" :auto-size="{ minRows: 1}"/>
                                        </a-form-model-item>
                                    </td>
                                    <td v-else>
                                        {{ form.fccdd }}
                                    </td>
                                </tr>
                                <tr>
                                    <th>出差开始时间</th>
                                    <td v-if="linkName=='出差申请' || linkName == '数据修订'">
                                        <a-form-model-item ref="fccksrq" prop="fccksrq">
                                            <a-input-group compact>
                                                <a-date-picker
                                                    style="width: 60%"
                                                    v-model="form.fccksrq"
                                                    type="date"
                                                    placeholder=""
                                                    @change="date1Change"/>
                                                <a-select
                                                    style="width: 40%"
                                                    default-value="08:00"
                                                    v-model="form.fcckssj"
                                                    @change="getTime">
                                                    <a-select-option value="08:00">
                                                        08:00
                                                    </a-select-option>
                                                    <a-select-option value="12:00">
                                                        12:00
                                                    </a-select-option>
                                                    <a-select-option value="18:00">
                                                        18:00
                                                    </a-select-option>
                                                </a-select>
                                            </a-input-group>
                                        </a-form-model-item>
                                    </td>
                                    <td v-else>{{ form.fccksrq +' '+form.fcckssj }}</td>
                                    <th>出差结束时间</th>
                                    <td v-if="linkName=='出差申请' || linkName == '数据修订'">
                                        <a-form-model-item ref="fccjsrq" prop="fccjsrq">
                                            <a-input-group compact>
                                                <a-date-picker
                                                    style="width: 60%"
                                                    v-model="form.fccjsrq"
                                                    type="date"
                                                    placeholder=""
                                                    @change="date2Change"/>
                                                <a-select
                                                    style="width: 40%"
                                                    default-value="18:00"
                                                    v-model="form.fccjssj"
                                                    @change="getTime">
                                                    <a-select-option value="08:00">
                                                        08:00
                                                    </a-select-option>
                                                    <a-select-option value="12:00">
                                                        12:00
                                                    </a-select-option>
                                                    <a-select-option value="18:00">
                                                        18:00
                                                    </a-select-option>
                                                </a-select>
                                            </a-input-group>
                                        </a-form-model-item>
                                    </td>
                                    <td v-else>{{ form.fccjsrq +' '+form.fccjssj }}</td>
                                </tr>
                                <tr>
                                    <th>出差事由</th>
                                    <td v-if="linkName == '出差申请'" colspan="3">
                                        <a-form-model-item prop="fccsy">
                                            <a-textarea v-model="form.fccsy" placeholder="请输入出差事由:" :auto-size="{ minRows: 2}"/>
                                        </a-form-model-item>
                                    </td>
                                    <td v-else colspan="3" class="text-align-left">
                                        {{ form.fccsy }}
                                    </td>
                                </tr>
                                <tr>
                                    <th>本科（室）<br/>领导意见</th>
                                    <td v-if="linkName == '科室审核' || linkName == '数据修订'" colspan="3">
                                        <a-form-model-item ref="fksldyj" prop="fksldyj">
                                            <reviewOpinions
                                              ref="reviewOpinionsRefKs"
                                              @getInputOpinion="getInputOpinion"
                                              @openOpinions="ksOpinions"
                                              @change="fksldyjChange"
                                              v-decorator="[
                                                'fksldyj', {initialValue:form.fksldyj,rules: rules.fksldyj}]"/>
                                        </a-form-model-item>
                                        <div v-if="linkName == '数据修订'" class="yjqm-right-bottom">
                                            <a-input
                                                v-model="form.fksldyjr"
                                                @click="checkMan('fksldyjr',form.fksldyjr)"
                                                placeholder=""
                                                class="checkMan-Xiu">
                                            </a-input>
                                            <a-date-picker
                                                show-time
                                                placeholder=""
                                                v-model="form.fksldyjsj"
                                                @change="timeChang($event,'fksldyjsj')"
                                                class="checkTime-Xiu"
                                                />
                                        </div>
                                    </td>
                                    <td v-else colspan="3">
                                        <div>
                                            <p class="text-align-left">{{ form.fksldyj }}</p>
                                            <div class="yjqm-right-bottom">
                                                <img v-if="getUrl('科室审核') && form.fksldyjsj" :src="getUrl('科室审核')" class="yjqmImg"/>
                                                <span v-else class="yjqmImg">{{ form.fksldyjr }}</span>
                                                <span>{{ form.fksldyjsj }}</span>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <th>办公室<br/>派车意见</th>
                                    <td v-if="linkName == '办公室审核' || linkName == '数据修订'" colspan="3">
                                        <a-form-model-item ref="fbgspcyj" prop="fbgspcyj">
                                            <reviewOpinions
                                              ref="reviewOpinionsRefBgs"
                                              @getInputOpinion="getInputOpinion"
                                              @openOpinions="bgsOpinions"
                                              v-decorator="[
                                                'fbgspcyj', {initialValue:form.fbgspcyj,rules: rules.fbgspcyj}]"/>
                                        </a-form-model-item>
                                        <div v-if="linkName == '数据修订'" class="yjqm-right-bottom">
                                            <a-input
                                                v-model="form.fbgspcyjr"
                                                @click="checkMan('fbgspcyjr',form.fbgspcyjr)"
                                                placeholder=""
                                                class="checkMan-Xiu">
                                            </a-input>
                                            <a-date-picker
                                                show-time
                                                placeholder=""
                                                v-model="form.fbgspcyjsj"
                                                @change="timeChang($event,'fbgspcyjsj')"
                                                class="checkTime-Xiu"
                                                />
                                        </div>
                                    </td>
                                    <td v-else colspan="3">
                                        <div>
                                            <p class="text-align-left">{{ form.fbgspcyj }}</p>
                                            <div class="yjqm-right-bottom">
                                                <img v-if="getUrl('办公室审核') && form.fbgspcyjsj" :src="getUrl('办公室审核')" class="yjqmImg"/>
                                                <span v-else class="yjqmImg">{{ form.fbgspcyjr }}</span>
                                                <span>{{ form.fbgspcyjsj }}</span>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <th>中心分管<br/>领导意见</th>
                                    <td v-if="linkName == '中心分管领导审核' || linkName == '数据修订'" colspan="3">
                                        <a-form-model-item ref="fzxfgldyj" prop="fzxfgldyj">
                                            <reviewOpinions
                                              ref="reviewOpinionsRefZxfgld"
                                              @getInputOpinion="getInputOpinion"
                                              @openOpinions="zxfgldOpinions"
                                              v-decorator="[
                                                'fzxfgldyj', {initialValue:form.fzxfgldyj,rules: rules.fzxfgldyj}]"/>
                                        </a-form-model-item>
                                        <div v-if="linkName == '数据修订'" class="yjqm-right-bottom">
                                            <a-input
                                                v-model="form.fzxfgldyjr"
                                                @click="checkMan('fzxfgldyjr',form.fzxfgldyjr)"
                                                placeholder=""
                                                class="checkMan-Xiu">
                                            </a-input>
                                            <a-date-picker
                                                show-time
                                                placeholder=""
                                                v-model="form.fzxfgldyjsj"
                                                @change="timeChang($event,'fzxfgldyjsj')"
                                                class="checkTime-Xiu"
                                                />
                                        </div>
                                    </td>
                                    <td v-else colspan="3">
                                        <div>
                                            <p class="text-align-left">{{ form.fzxfgldyj }}</p>
                                            <div class="yjqm-right-bottom">
                                                <img v-if="getUrl('中心分管领导审核') && form.fzxfgldyjsj" :src="getUrl('中心分管领导审核')" class="yjqmImg"/>
                                                <span v-else class="yjqmImg">{{ form.fzxfgldyjr }}</span>
                                                <span>{{ form.fzxfgldyjsj }}</span>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <th>中心主要<br/>领导意见</th>
                                    <td v-if="linkName == '中心领导审核' || linkName == '数据修订'" colspan="3">
                                        <a-form-model-item ref="fzxzyldyj" prop="fzxzyldyj">
                                            <reviewOpinions
                                              ref="reviewOpinionsRefZxzyld"
                                              @getInputOpinion="getInputOpinion"
                                              @openOpinions="zxzyldOpinions"
                                              v-decorator="[
                                                'fzxzyldyj', {initialValue:form.fzxzyldyj,rules: rules.fzxzyldyj}]"/>
                                        </a-form-model-item>
                                        <div v-if="linkName == '数据修订'" class="yjqm-right-bottom">
                                            <a-input
                                                v-model="form.fzxzyldyjr"
                                                @click="checkMan('fzxzyldyjr',form.fzxzyldyjr)"
                                                placeholder=""
                                                class="checkMan-Xiu">
                                            </a-input>
                                            <a-date-picker
                                                show-time
                                                placeholder=""
                                                v-model="form.fzxzyldyjsj"
                                                @change="timeChang($event,'fzxzyldyjsj')"
                                                class="checkTime-Xiu"
                                                />
                                        </div>
                                    </td>
                                    <td v-else colspan="3">
                                        <div>
                                            <p class="text-align-left">{{ form.fzxzyldyj }}</p>
                                            <div class="yjqm-right-bottom">
                                                <img v-if="getUrl('中心领导审核') && form.fzxzyldyjsj" :src="getUrl('中心领导审核')" class="yjqmImg"/>
                                                <span v-else class="yjqmImg">{{ form.fzxzyldyjr }}</span>
                                                <span>{{ form.fzxzyldyjsj }}</span>
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                            <p style="color: #5ca3e5;">注：报销差旅时需附出差审批表</p>
                        </a-form-model>
                    </div>
                </a-tab-pane>
                <a-tab-pane v-if="linkName == '我的已办'" key="2" tab="流转记录">
                    <a-table
                        :columns="lzColumns"
                        :data-source="lzList"
                        bordered
                        style="border-color: #d9d9d9;font-weight: 600;text-align: center;"
                        :customRow="customRow">
                    </a-table>
                </a-tab-pane>
                <a-button
                    v-if="showPrintBtn(linkName,form.flczt,tabsKey)"
                    slot="tabBarExtraContent"
                    class="print-btn"
                    v-print="printObj">
                    打印
                </a-button>
            </a-tabs>
        </a-modal>
    </div>
</template>
<script>
import { initBzFlow,saveFlow,submitFlow,queryJobByJobId,returnUpperzdyFlowJob,flowJkPage,downMyQm,} from './service/index'
import store from '@/store'
import moment from 'moment'
export default {
    props:{
        formData:{
            type:[Array,Object],
            default: () => {},
            required:false
        },
        linkName: {
            type:String,
            default: '',
            required:false
        }
    },
    data() {
        return {
            moment:moment,
            loading: false,
            applicationFormVisible: false,
            tabsKey: '1',
            labelCol: { span: 8 },
            wrapperCol: { span: 24 },
            form: {
                fbgspcyj: "",
                fbgspcyjr: "",
                fbgspcyjsj: "",
                fbxzt: "",
                fccdd: "",
                fccjsrq: null,
                fccjssj: "18:00",
                fccksrq: null,
                fcckssj: "08:00",
                fccsy: "",
                fksldyj: "",
                fksldyjr: "",
                fksldyjsj: "",
                flczt: "",
                fsffqlc: "",
                ftbdw: "",
                ftbsj: "",
                fuserid: "",
                fxm: "",
                fzxfgldyj: "",
                fzxfgldyjr: "",
                fzxfgldyjsj: "",
                fzxzyldyj: "",
                fzxzyldyjr: "",
                fzxzyldyjsj: "",
                id: "",
            },
            kongForm: {},
            rules:{
              fccdd: [
                { required: true, message: '请输入出差地点', trigger: 'blur' }
              ],
              fccksrq: [
                { required: true, message: '请选择出差开始时间', trigger: 'change' }
              ],
              fccjsrq: [
                { required: true, message: '请选择出差结束时间', trigger: 'change' },
              ],
              fccsy: [
                { required: true, message: '请输入出差事由', trigger: 'blur' }
              ],
              fksldyj: [
                { required: true, message: '请输入本科（室）意见', trigger: 'blur' }
              ],
              fbgspcyj: [
                { required: true, message: '请输入办公室意见', trigger: 'blur' }
              ],
              fzxfgldyj: [
                { required: true, message: '请输入中心分管领导意见', trigger: 'blur' }
              ],
              fzxzyldyj: [
                { required: true, message: '请输入中心主要领导意见', trigger: 'blur' }
              ],
            },
            imgList: [
                {fhjmc:'科室审核',url: ''},
                {fhjmc:'办公室审核',url: ''},
                {fhjmc:'中心分管领导审核',url: ''},
                {fhjmc:'中心领导审核',url: ''},
            ],
            lzColumns: [
            {
            title: '环节名称',
            dataIndex: 'fhjmc',
            key: 'fhjmc',
            width: 150,
            },{
            title: '待办人',
            dataIndex: 'fdbr',
            key: 'fdbr',
            width: 150,
            align: 'center'
            },{
            title: '办理人',
            dataIndex: 'fblr',
            key: 'fblr',
            width: 100,
            },{
            title: '发送时间',
            dataIndex: 'ffssj',
            key: 'ffssj',
            width: 170,
            },{
            title: '办理时间',
            dataIndex: 'fblsj',
            key: 'fblsj',
            width: 170,
            },{
            title: '办理状态',
            dataIndex: 'fblzt',
            key: 'fblzt',
            width: 100,
            },{
            title: '办理类型',
            dataIndex: 'fbllx',
            key: 'fbllx',
            width: 300,
            },{
            title: '办理意见',
            dataIndex: 'fblyj',
            key: 'fblyj',
            align: 'center'
            },
            ],
            lzList: [],
            printObj:{
                id:"printTest", //需要打印的id名称
                popTitle:"xx壮族自治区食品药品审评查验中心公务出差审批表",//文档的名称
                // preview:true,//预览功能，不好用
                zIndex:'20002',
                beforeOpenCallback(vue){
                    //console.log('打印回调',vue)
                },
                openCallback (vue) {//打开之前
                    //console.log('打开之前',vue)
                },
                closeCallback (vue) {//关闭了打印工具
                    //console.log('关闭了打印工具')
                },
            },
        }
    },
    watch: {
        formData(newval,oldVal){
        //console.log(newval)
            if(newval.id){
                this.form = newval
                this.getLiuZuanData(newval.id)
            }
        },
    },
    created() {
        this.getName()
        this.kongForm = JSON.parse(JSON.stringify(this.form))
    },
    mounted(){
        this.kongForm = JSON.parse(JSON.stringify(this.form))
    },
    methods: {
        showPrintBtn(linkName,flczt,tabsKey){
            if(linkName == '我的已办' && flczt == '流程结束' && tabsKey == '1'){
                return true
            } else {
                return false
            }
        },
        getName(){
            this.form.fxm = store.getters.userInfo.realname
        },
        callback(key) {
        // //console.log(key);
            this.tabsKey = key
        },
        customRow() {
            return {
                style: {
                    'font-size' : '16px',
                    'text-align' : 'center'
                },
            }
        },
        closeVisible(){
            this.$emit('success')
            this.applicationFormVisible = false
            // this.resetForm()
            this.form = {...this.kongForm}
        },
        getLiuZuanData(id){
            flowJkPage({oaid:id}).then(res => {
                let arr1 = []
                    arr1 = res.result.records
                var arr2 = new Array();
                for (let i = arr1.length - 1; i >= 0; i--) {
                arr2.push(arr1[i]);
                }
                // //console.log('arr2',arr2)
                this.lzList = []
                arr1.forEach(item => {
                item = {
                    ...item,
                    key: item.jobid
                }
                this.lzList.push(item)
                //console.log('IMG')
                this.imgList.forEach((items,a)=> {
                        if(item.fdbrid){
                        if(items.fhjmc == item.fhjmc){
                            downMyQm({id:item.fdbrid}).then(resa => {
                              if(resa.code){
                                this.imgList[a].url = null
                              } else {
                                this.imgList[a].url = "data:image/png;base64," +
                                btoa( new Uint8Array(resa).reduce( (data, byte) => data + String.fromCharCode(byte), "" ))
                              }
                            })
                        }
                        } else {}
                    })
                })
            })
        },
        getUrl(ids){
            let url = ''
            this.imgList.forEach(item => {
                if(item.fhjmc == ids){
                url = item.url
                }
            })
            return url
        },
        date1Change(val){
            this.form.fccksrq = val==null?null:moment(val).format('YYYY-MM-DD')
            this.getTime()
        },
        date2Change(val){
            this.form.fccjsrq = val==null?null:moment(val).format('YYYY-MM-DD')
            this.getTime()
        },
        getTime(){
            if(this.form.fccksrq !== null && this.form.fccjsrq !== null){
                let startTime = new Date(Date.parse(this.form.fccksrq + ' ' + this.form.fcckssj)).getTime()
                let ensTime = new Date(Date.parse(this.form.fccjsrq + ' ' + this.form.fccjssj)).getTime()
                // //console.log(startTime,ensTime)
                if(startTime >= ensTime){
                    // this.form.fccksrq = null
                    // this.form.fccjsrq = null
                    this.$message.warning('当前时间选择无效，出差开始时间需大于出差结束时间，请重新选择')
                }
            }
        },
        // 打开意见弹窗
        ksOpinions(){
            this.$refs.reviewOpinionsRefKs.getData({opinionType:'ksIdeaType',oldVal:this.form.fksldyj,valueData:{hjmc:'fksldyj'}})
        },
        bgsOpinions(){
            this.$refs.reviewOpinionsRefBgs.getData({opinionType:'bgsIdeaType',oldVal:this.form.fbgspcyj,valueData:{hjmc:'fbgspcyj'}})
        },
        zxfgldOpinions(){
            this.$refs.reviewOpinionsRefZxfgld.getData({opinionType:'zxfgldIdeaType',oldVal:this.form.fzxfgldyj,valueData:{hjmc:'fzxfgldyj'}})
        },
        zxzyldOpinions(){
            this.$refs.reviewOpinionsRefZxzyld.getData({opinionType:'zxzyldIdeaType',oldVal:this.form.fzxzyldyj,valueData:{hjmc:'fzxzyldyj'}})
        },
        // 意见弹窗
        getInputOpinion(val,valueData){
            let data = this.form
            data[valueData.hjmc] = val
            //console.log(this.form)
        },
        fksldyjChange(){
            //console.log(this.form.fksldyj)
            //console.log(this.form)
        },
        onSave(str) {
          let data= {}
          if(str == '保存'){
              if(this.linkName == '出差申请'){
                  if(this.form.id){
                      data = {
                          fxm: this.form.fxm,
                          fccdd: this.form.fccdd,
                          fccsy: this.form.fccsy,
                          fccksrq: this.form.fccksrq,
                          fcckssj: this.form.fcckssj,
                          fccjsrq: this.form.fccjsrq,
                          fccjssj: this.form.fccjssj,
                          id: this.form.id
                      }
                      this.loading = true
                      this.initBzFlowFuntion(data,str)
                  } else {
                      data = {
                          fxm: this.form.fxm,
                          fccdd: this.form.fccdd,
                          fccsy: this.form.fccsy,
                          fccksrq: this.form.fccksrq,
                          fcckssj: this.form.fcckssj,
                          fccjsrq: this.form.fccjsrq,
                          fccjssj: this.form.fccjssj,
                          id: this.form.id
                      }
                      this.loading = true
                      this.initBzFlowFuntion(data,str)
                  }
              } else if(this.linkName == '科室审核'){
                  data = {
                      jobid: this.form.jobid,
                      oaid: this.form.id,
                      map: {
                          fksldyj: this.form.fksldyj,
                          fksldyjr: this.form.fksldyjr,
                          fksldyjsj: this.form.fksldyjsj
                      },
                      opinion: this.form.fksldyj,
                      currentNode: "",
                      dbrid: "",
                      lcmbCode: "",
                      nextNode: "",
                      nextNodeId: "",
                      smgflag: ""
                  }
                    this.loading = true
                    this.saveFlowFuntion(data)
              } else if(this.linkName == '办公室审核'){
                  data = {
                      jobid: this.form.jobid,
                      oaid: this.form.id,
                      map: {
                          fbgspcyj: this.form.fbgspcyj,
                          fbgspcyjr: this.form.fbgspcyjr,
                          fbgspcyjsj: this.form.fbgspcyjsj
                      },
                      opinion: this.form.fbgspcyj,
                      currentNode: "",
                      dbrid: "",
                      lcmbCode: "",
                      nextNode: "",
                      nextNodeId: "",
                      smgflag: ""
                  }
                  this.saveFlowFuntion(data)
              } else if(this.linkName == '中心分管领导审核'){
                  data = {
                      jobid: this.form.jobid,
                      oaid: this.form.id,
                      map: {
                          fzxfgldyj: this.form.fzxfgldyj,
                          fzxfgldyjr: this.form.fzxfgldyjr,
                          fzxfgldyjsj: this.form.fzxfgldyjsj
                      },
                      opinion: this.form.fzxfgldyj,
                      currentNode: "",
                      dbrid: "",
                      lcmbCode: "",
                      nextNode: "",
                      nextNodeId: "",
                      smgflag: ""
                  }
                  this.saveFlowFuntion(data)
              } else if(this.linkName == '中心领导审核'){
                  data = {
                      jobid: this.form.jobid,
                      oaid: this.form.id,
                      map: {
                          fzxzyldyj: this.form.fzxzyldyj,
                          fzxzyldyjr: this.form.fzxzyldyjr,
                          fzxzyldyjsj: this.form.fzxzyldyjsj,
                      },
                      opinion: this.form.fzxzyldyj,
                      currentNode: "",
                      dbrid: "",
                      lcmbCode: "",
                      nextNode: "",
                      nextNodeId: "",
                      smgflag: ""
                  }
                  this.saveFlowFuntion(data)
              }
          } else if(str == '提交'){
              if(this.linkName == '出差申请'){
                  if(this.form.id){
                      data = {
                          jobid: this.form.jobid,
                          oaid: this.form.id,
                          map: {
                              fxm: this.form.fxm,
                              fccdd: this.form.fccdd,
                              fccsy: this.form.fccsy,
                              fccksrq: this.form.fccksrq,
                              fcckssj: this.form.fcckssj,
                              fccjsrq: this.form.fccjsrq,
                              fccjssj: this.form.fccjssj,
                          },
                          opinion: this.form.fksshyj,
                          currentNode: "",
                          dbrid: "",
                          lcmbCode: "",
                          nextNode: "",
                          nextNodeId: "",
                          smgflag: ""
                      }
                      this.loading = true
                      this.submitFlowFuntion(data)
                  } else {
                      data = {
                          id: '',
                          fxm: this.form.fxm,
                          fccdd: this.form.fccdd,
                          fccsy: this.form.fccsy,
                          fccksrq: this.form.fccksrq,
                          fcckssj: this.form.fcckssj,
                          fccjsrq: this.form.fccjsrq,
                          fccjssj: this.form.fccjssj,
                          fsffqlc: '是',
                      }
                      this.loading = true
                      this.initBzFlowFuntion(data,str,'1')
                  }
              } else if(this.linkName == '科室审核'){
                  data = {
                      jobid: this.form.jobid,
                      oaid: this.form.id,
                      map: {
                          fksldyj: this.form.fksldyj,
                          fksldyjr: this.form.fksldyjr,
                          fksldyjsj: this.form.fksldyjsj
                      },
                      opinion: this.form.fksldyj,
                      currentNode: "",
                      dbrid: "",
                      lcmbCode: "",
                      nextNode: "",
                      nextNodeId: "",
                      smgflag: ""
                  }
                  this.submitFlowFuntion(data)
              } else if(this.linkName == '办公室审核'){
                  data = {
                      jobid: this.form.jobid,
                      oaid: this.form.id,
                      map: {
                          fbgspcyj: this.form.fbgspcyj,
                          fbgspcyjr: this.form.fbgspcyjr,
                          fbgspcyjsj: this.form.fbgspcyjsj
                      },
                      opinion: this.form.fbgspcyj,
                      currentNode: "",
                      dbrid: "",
                      lcmbCode: "",
                      nextNode: "",
                      nextNodeId: "",
                      smgflag: ""
                  }
                  this.submitFlowFuntion(data)
              } else if(this.linkName == '中心分管领导审核'){
                  data = {
                      jobid: this.form.jobid,
                      oaid: this.form.id,
                      map: {
                          fzxfgldyj: this.form.fzxfgldyj,
                          fzxfgldyjr: this.form.fzxfgldyjr,
                          fzxfgldyjsj: this.form.fzxfgldyjsj
                      },
                      opinion: this.form.fzxfgldyj,
                      currentNode: "",
                      dbrid: "",
                      lcmbCode: "",
                      nextNode: "",
                      nextNodeId: "",
                      smgflag: ""
                  }
                  this.submitFlowFuntion(data)
              } else if(this.linkName == '中心领导审核'){
                  if(this.form.fxmyszbid !== ''){
                      data = {
                          jobid: this.form.jobid,
                          oaid: this.form.id,
                          map: {
                              fzxzyldyj: this.form.fzxzyldyj,
                              fzxzyldyjr: this.form.fzxzyldyjr,
                              fzxzyldyjsj: this.form.fzxzyldyjsj,
                          },
                          opinion: this.form.fzxzyldyj,
                          currentNode: "",
                          dbrid: "",
                          lcmbCode: "",
                          nextNode: "",
                          nextNodeId: "",
                          smgflag: ""
                      }
                      this.submitFlowFuntion(data)
                  } else {
                      this.$message.warning('请选择项目预算指标')
                  }
              }
          }
        },
        onSubmit(str) {
            this.$refs.ruleForm.validate(valid => {
                if (valid) {
                    var that = this
                    that.$confirm({
                        title: '您确定要提交吗?',
                        onOk() {
                            let data= {}
                            if(str == '保存'){
                                if(that.linkName == '出差申请'){
                                    if(that.form.id){
                                        data = {
                                            fxm: that.form.fxm,
                                            fccdd: that.form.fccdd,
                                            fccsy: that.form.fccsy,
                                            fccksrq: that.form.fccksrq,
                                            fcckssj: that.form.fcckssj,
                                            fccjsrq: that.form.fccjsrq,
                                            fccjssj: that.form.fccjssj,
                                            id: that.form.id
                                        }
                                        that.loading = true
                                        that.initBzFlowFuntion(data,str)
                                    } else {
                                        data = {
                                            fxm: that.form.fxm,
                                            fccdd: that.form.fccdd,
                                            fccsy: that.form.fccsy,
                                            fccksrq: that.form.fccksrq,
                                            fcckssj: that.form.fcckssj,
                                            fccjsrq: that.form.fccjsrq,
                                            fccjssj: that.form.fccjssj,
                                            id: that.form.id
                                        }
                                        that.loading = true
                                        that.initBzFlowFuntion(data,str)
                                    }
                                } else if(that.linkName == '科室审核'){
                                    data = {
                                        jobid: that.form.jobid,
                                        oaid: that.form.id,
                                        map: {
                                            fksldyj: that.form.fksldyj,
                                            fksldyjr: that.form.fksldyjr,
                                            fksldyjsj: that.form.fksldyjsj
                                        },
                                        opinion: that.form.fksldyj,
                                        currentNode: "",
                                        dbrid: "",
                                        lcmbCode: "",
                                        nextNode: "",
                                        nextNodeId: "",
                                        smgflag: ""
                                    }
                                    that.saveFlowFuntion(data)
                                } else if(that.linkName == '办公室审核'){
                                    data = {
                                        jobid: that.form.jobid,
                                        oaid: that.form.id,
                                        map: {
                                            fbgspcyj: that.form.fbgspcyj,
                                            fbgspcyjr: that.form.fbgspcyjr,
                                            fbgspcyjsj: that.form.fbgspcyjsj
                                        },
                                        opinion: that.form.fbgspcyj,
                                        currentNode: "",
                                        dbrid: "",
                                        lcmbCode: "",
                                        nextNode: "",
                                        nextNodeId: "",
                                        smgflag: ""
                                    }
                                    that.saveFlowFuntion(data)
                                } else if(that.linkName == '中心分管领导审核'){
                                    data = {
                                        jobid: that.form.jobid,
                                        oaid: that.form.id,
                                        map: {
                                            fzxfgldyj: that.form.fzxfgldyj,
                                            fzxfgldyjr: that.form.fzxfgldyjr,
                                            fzxfgldyjsj: that.form.fzxfgldyjsj
                                        },
                                        opinion: that.form.fzxfgldyj,
                                        currentNode: "",
                                        dbrid: "",
                                        lcmbCode: "",
                                        nextNode: "",
                                        nextNodeId: "",
                                        smgflag: ""
                                    }
                                    that.saveFlowFuntion(data)
                                } else if(that.linkName == '中心领导审核'){
                                    data = {
                                        jobid: that.form.jobid,
                                        oaid: that.form.id,
                                        map: {
                                            fzxzyldyj: that.form.fzxzyldyj,
                                            fzxzyldyjr: that.form.fzxzyldyjr,
                                            fzxzyldyjsj: that.form.fzxzyldyjsj,
                                        },
                                        opinion: that.form.fzxzyldyj,
                                        currentNode: "",
                                        dbrid: "",
                                        lcmbCode: "",
                                        nextNode: "",
                                        nextNodeId: "",
                                        smgflag: ""
                                    }
                                    that.saveFlowFuntion(data)
                                }
                            } else if(str == '提交'){
                                if(that.linkName == '出差申请'){
                                    if(that.form.id){
                                        data = {
                                            jobid: that.form.jobid,
                                            oaid: that.form.id,
                                            map: {
                                                fxm: that.form.fxm,
                                                fccdd: that.form.fccdd,
                                                fccsy: that.form.fccsy,
                                                fccksrq: that.form.fccksrq,
                                                fcckssj: that.form.fcckssj,
                                                fccjsrq: that.form.fccjsrq,
                                                fccjssj: that.form.fccjssj,
                                            },
                                            opinion: that.form.fksshyj,
                                            currentNode: "",
                                            dbrid: "",
                                            lcmbCode: "",
                                            nextNode: "",
                                            nextNodeId: "",
                                            smgflag: ""
                                        }
                                        that.loading = true
                                        that.submitFlowFuntion(data)
                                    } else {
                                        data = {
                                            id: '',
                                            fxm: that.form.fxm,
                                            fccdd: that.form.fccdd,
                                            fccsy: that.form.fccsy,
                                            fccksrq: that.form.fccksrq,
                                            fcckssj: that.form.fcckssj,
                                            fccjsrq: that.form.fccjsrq,
                                            fccjssj: that.form.fccjssj,
                                            fsffqlc: '是',
                                        }
                                        that.loading = true
                                        that.initBzFlowFuntion(data,str,'1')
                                    }
                                } else if(that.linkName == '科室审核'){
                                    data = {
                                        jobid: that.form.jobid,
                                        oaid: that.form.id,
                                        map: {
                                            fksldyj: that.form.fksldyj,
                                            fksldyjr: that.form.fksldyjr,
                                            fksldyjsj: that.form.fksldyjsj
                                        },
                                        opinion: that.form.fksldyj,
                                        currentNode: "",
                                        dbrid: "",
                                        lcmbCode: "",
                                        nextNode: "",
                                        nextNodeId: "",
                                        smgflag: ""
                                    }
                                    that.submitFlowFuntion(data)
                                } else if(that.linkName == '办公室审核'){
                                    data = {
                                        jobid: that.form.jobid,
                                        oaid: that.form.id,
                                        map: {
                                            fbgspcyj: that.form.fbgspcyj,
                                            fbgspcyjr: that.form.fbgspcyjr,
                                            fbgspcyjsj: that.form.fbgspcyjsj
                                        },
                                        opinion: that.form.fbgspcyj,
                                        currentNode: "",
                                        dbrid: "",
                                        lcmbCode: "",
                                        nextNode: "",
                                        nextNodeId: "",
                                        smgflag: ""
                                    }
                                    that.submitFlowFuntion(data)
                                } else if(that.linkName == '中心分管领导审核'){
                                    data = {
                                        jobid: that.form.jobid,
                                        oaid: that.form.id,
                                        map: {
                                            fzxfgldyj: that.form.fzxfgldyj,
                                            fzxfgldyjr: that.form.fzxfgldyjr,
                                            fzxfgldyjsj: that.form.fzxfgldyjsj
                                        },
                                        opinion: that.form.fzxfgldyj,
                                        currentNode: "",
                                        dbrid: "",
                                        lcmbCode: "",
                                        nextNode: "",
                                        nextNodeId: "",
                                        smgflag: ""
                                    }
                                    that.submitFlowFuntion(data)
                                } else if(that.linkName == '中心领导审核'){
                                    if(that.form.fxmyszbid !== ''){
                                        data = {
                                            jobid: that.form.jobid,
                                            oaid: that.form.id,
                                            map: {
                                                fzxzyldyj: that.form.fzxzyldyj,
                                                fzxzyldyjr: that.form.fzxzyldyjr,
                                                fzxzyldyjsj: that.form.fzxzyldyjsj,
                                            },
                                            opinion: that.form.fzxzyldyj,
                                            currentNode: "",
                                            dbrid: "",
                                            lcmbCode: "",
                                            nextNode: "",
                                            nextNodeId: "",
                                            smgflag: ""
                                        }
                                        that.submitFlowFuntion(data)
                                    } else {
                                        that.$message.warning('请选择项目预算指标')
                                    }
                                }
                            }
                        },
                        onCancel() {},
                    });
                } else {
                    //console.log('error submit!!');
                    return false;
                }
            });
        },
        initBzFlowFuntion(data,str,type){
            initBzFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.form.id = res.result.nkMap.id
                    this.form.jobid = res.result.jobMap.id
                    if(str == '提交'){
                        this.closeVisible()
                    }
                } else {
                    this.$message.warning(res.message)
                }
                this.loading = false
            })
        },
        saveFlowFuntion(data){
            saveFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                } else {
                    this.$message.warning(res.message)
                }
            })
        },
        submitFlowFuntion(data){
            submitFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.warning(res.message)
                }
                this.loading = false
            })
        },
        // 退回
        returnClick(){
            this.$refs.ruleForm.validate(valid => {
                if (valid) {
                    queryJobByJobId({jobid:this.form.jobid}).then(res => {
                        let list = res.result.jobHistoryList
                        list.forEach(item => {
                            if(item.fhjmc == '出差申请'){
                                this.returnFuntion(this.form.jobid,item.id)
                            }
                        })
                    })
                }
            })
        },
        returnFuntion(jobid,ids){
            let returnStr = ''
            if(this.linkName == '出差申请'){
                returnStr = this.form.fksshyj
            } else if(this.linkName == '科室审核'){
                returnStr = this.form.fksldyj
            } else if(this.linkName == '办公室审核'){
                returnStr = this.form.fbgspcyj
            } else if(this.linkName == '中心分管领导审核'){
                returnStr = this.form.fzxfgldyj
            } else if(this.linkName == '中心领导审核'){
                returnStr = this.form.fzxzyldyj
            }
            let data = {
                jobid: jobid,
                opinion: returnStr,
                shjid: ids,
                lcmbbm: '',
                smgflag: '',
                smsContent: '',
            }
            returnUpperzdyFlowJob(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.error(res.message)
                }
            })
        },
    },
}
</script>
<style>
@import url('../../css/oaLess.css');
@import url('../../css/oaClass.css');
</style>
